package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.VehicleBlacklist;
import com.ruoyi.system.service.IVehicleBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/black")
public class BlackListController extends BaseController {

    @Value("${appId}")
    private String appId;

    @Value("${parkId}")
    private String parkId;

    @Autowired
    private IVehicleBlacklistService vehicleBlacklistService;

    /**
     * 查询【黑名单】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(VehicleBlacklist vehicleBlacklist)
    {
        if(vehicleBlacklist.getAppId().equals(appId) && vehicleBlacklist.getParkId().equals(parkId)) {
            startPage();
            List<VehicleBlacklist> list = vehicleBlacklistService.selectVehicleBlacklistList(vehicleBlacklist);
            return getDataTable(list);
        }else{
            return getDataTable(null);
        }
    }

    /**
     * 获取【黑名单】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(vehicleBlacklistService.selectVehicleBlacklistById(id));
    }

    /**
     * 新增【黑名单】
     */
    @Log(title = "【黑名单】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleBlacklist vehicleBlacklist)
    {
        return toAjax(vehicleBlacklistService.insertVehicleBlacklist(vehicleBlacklist));
    }

    /**
     * 修改【黑名单】
     */
    @Log(title = "【黑名单】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleBlacklist vehicleBlacklist)
    {
        return toAjax(vehicleBlacklistService.updateVehicleBlacklist(vehicleBlacklist));
    }

    /**
     * 删除【黑名单】
     */
    @Log(title = "【黑名单】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vehicleBlacklistService.deleteVehicleBlacklistByIds(ids));
    }
}
